package com.example.shop_2210.adapter

import android.graphics.Color
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.ExplosiveMoney
import com.example.shop_2210.R

/**
 * 首页分类适配器
 */
class CateHomeAdapter:BaseQuickAdapter<ExplosiveMoney,BaseViewHolder>(R.layout.item_cate_home) {
    //设置默认选中
    var selectedType = 4
    override fun convert(holder: BaseViewHolder, item: ExplosiveMoney) {
        holder.setText(R.id.tv_name,item.name)
        holder.setText(R.id.tv_info,item.info)
        if(item.type.toInt()==selectedType){
            //选中文字颜色为红色
            holder.getView<TextView>(R.id.tv_name).setTextColor(Color.RED)
            holder.getView<TextView>(R.id.tv_info).setTextColor(Color.RED)
        }else{
            //未选中的文字颜色为灰色
            holder.getView<TextView>(R.id.tv_name).setTextColor(Color.GRAY)
            holder.getView<TextView>(R.id.tv_info).setTextColor(Color.GRAY)
        }
    }
    //修改选中的type
    fun setType(type:Int){
        selectedType  = type
        notifyDataSetChanged()
    }

}